package factory;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @pakager_name:Factory
 * @description:创建SqlSession的单例（工厂）
 * @author: 周铖鑫
 * @time: 2020/12/6 17:56
 */
public class FKSqlSessionFactory {
    private static SqlSessionFactory sqlSessionFactory=null;
    static {
        try(InputStream inputStream= Resources.getResourceAsStream("mybatis-config.xml");)
        {
            sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }

    public static SqlSessionFactory getSqlSessionFactory() {
        return sqlSessionFactory;
    }
}
